package com.ude.pim.interceptor;

import com.alibaba.fastjson.JSON;
import com.ude.pim.common.BaseContext;
import com.ude.pim.common.R;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PIMInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        response.setHeader("Access-Control-Allow-Origin", "http://192.168.1.176:8080"); // 允许的前端地址
//        response.setHeader("Access-Control-Allow-Methods", "*"); // 允许所有HTTP方法
//        response.setHeader("Access-Control-Allow-Headers", "*"); // 允许所有请求头
//        response.setHeader("Access-Control-Allow-Credentials", "true"); // 允许发送认证信息（例如Cookies）

        return true;
//        //判断Session是否有登录属性
//        Object user = request.getSession().getAttribute("user");
//        //有，则登录
//        if(user !=null){
//            Long userId = (Long) user;
//            BaseContext.setId(userId);
//            return true;
//        }
//        //没有，则返回登录界面
//        response.getWriter().write(JSON.toJSONString(R.error("NOTLOGIN")));
//        return false;
    }
}

